package com.javer.dao;

import java.util.Map;

import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import com.javer.dao.support.DataSourceDaoSupport;

@Repository
public class CommDao extends DataSourceDaoSupport {

	public void deleteByIds(String tableName, int[] ids) {
		Assert.notNull(ids);
		Assert.notNull(tableName);
		StringBuilder sb = new StringBuilder("(");
		for (int id : ids) {
			sb.append(id).append(",");
		}
		if (sb.length() > 1) {
			sb.deleteCharAt(sb.length() - 1);
			sb.append(")");
			jdbcTemplate.update("delete from "+ tableName +" where id in " + sb);
		}
	}
	
	public void deleteByProperty(String tableName, String propertyName, String propertyValue) {
		jdbcTemplate.update("delete from " + tableName + " where "+ propertyName +"=?", new Object[]{propertyValue});
	}
	
	public Map getMapById(String tableName, int id) {
		return jdbcTemplate.queryForMap("select * from " + tableName + " where id=" + id);
	}
}
